﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BLL;

public partial class _Default : System.Web.UI.Page
{
    BLL.UserBean userBean = null;
    ReadParamtes bllParam = new ReadParamtes();

    protected void Page_Load(object sender, EventArgs e)
    {
        userBean = new UserBean();

        if (!IsPostBack)
        {
            if (Session["LoginUser"] == null)
            {
                this.right1.Visible = true;
                this.right2.Visible = false;  
            }
            else
            {
                this.right1.Visible = false;
                this.right2.Visible = true;
                this.Lbl_User.Text = Session["LoginUser"].ToString();
            }
       }

        //显示公告
        this.dl_NewsInfo1.DataSource = bllParam.GetNewsInfo("6430977f-e44b-40aa-a3b8-c6e21f764631");
        this.dl_NewsInfo1.DataBind();

        this.dl_NewsInfo2.DataSource = bllParam.GetNewsInfo("89646ccc-52b6-40ef-9b4a-5b72cbd91d02");
        this.dl_NewsInfo2.DataBind();

        this.dl_NewsInfo3.DataSource = bllParam.GetNewsInfo("192e1bab-5554-44f7-a2fb-37ec24ccbbd0");
        this.dl_NewsInfo3.DataBind();

        this.dl_NewsInfo4.DataSource = bllParam.GetNewsInfo("0517e6eb-5153-4945-b459-ce9898bf9a69");
        this.dl_NewsInfo4.DataBind();
    }


    protected void ImgBtnLogin_Click(object sender, ImageClickEventArgs e)
    {
        //比对验证码
        string validateCode = this.Txt_ValidateCode.Text.Trim();
        string mobile = WebUtility.replaceStr(this.Txt_Mobile.Text.Trim());
        string pwd = WebUtility.replaceStr(this.Txt_Pwd.Text.Trim());
        string userType = this.RdBtnListType.SelectedValue;// 1:个人；2：企业
        bool isValidated = false;

        string systemValidateCode = "";
        if (Session["webValidateCode"] != null)
        {
            systemValidateCode = Session["webValidateCode"].ToString();

        }
        //验证码相同
        if (string.Compare(validateCode, systemValidateCode, true) == 0)
        {
            isValidated = userBean.ValidateLoginUser(mobile, pwd, userType);
            if (isValidated == true)
            {
                Session["LoginUser"] = mobile;
                Response.Redirect(WebUtility.getWebRootPath() + "/MyLy/Mylyindex.aspx");  
            }
            else
            {
                //error=2 账户名和密码不匹配，或该用户不存在
                Response.Redirect(WebUtility.getWebRootPath() + "/Login/Login.aspx?error=2");
            }
        }
        else 
        {
            //error=1 验证码错误
            Response.Redirect(WebUtility.getWebRootPath() + "/Login/Login.aspx?error=1");
        }
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Session.Remove("LoginUser");
        Response.Redirect(WebUtility.getWebRootPath() + "/Logout.aspx");
    }
}
